package com.example.administrator.u17.adapter;

import android.content.Context;
import android.content.Intent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.administrator.u17.R;
import com.example.administrator.u17.activity.ReadActivity;
import com.example.administrator.u17.modle.ZhangjieInfo;

import java.util.List;

/**
 * Created by Administrator on 2016/11/14.
 */

public class ZhangjieBaseAdapter extends BaseAdapter {
    private List<ZhangjieInfo.DataBean.ReturnDataBean.ChapterListBean> list;
    private Context context;

    public ZhangjieBaseAdapter(List<ZhangjieInfo.DataBean.ReturnDataBean.ChapterListBean> list, List<ZhangjieInfo.DataBean.ReturnDataBean.OtherWorksBean> list3, Context context) {
        this.list = list;
        this.context = context;
    }

    @Override
    public int getCount() {
        return list.size() / 2;
    }

    @Override
    public Object getItem(int i) {
        return list.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(final int i, View view, ViewGroup viewGroup) {
        ViewHolder4 vh4;
        if (view == null) {
            view = View.inflate(context, R.layout.item_moren, null);
            vh4 = new ViewHolder4(view);
            view.setTag(vh4);
        } else {
            vh4 = (ViewHolder4) view.getTag();
        }
        vh4.tv.setText(list.get(i * 2).name);
        vh4.tv.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(context, ReadActivity.class);
                intent.putExtra("id", list.get(i * 2).chapter_id);
                context.startActivity(intent);
            }
        });
        vh4.tv2.setText(list.get(i * 2 + 1).name);
        vh4.tv2.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(context, ReadActivity.class);
                intent.putExtra("id", list.get(i * 2 + 1).chapter_id);
                context.startActivity(intent);
            }
        });



        if (list.get(i).type == 0) {
            vh4.iv.setVisibility(View.GONE);
            vh4.iv3.setVisibility(View.GONE);
            vh4.iv2.setVisibility(View.GONE);
            vh4.iv4.setVisibility(View.GONE);
        } else {
            vh4.iv2.setVisibility(View.GONE);
            vh4.iv4.setVisibility(View.GONE);
            vh4.iv.setVisibility(View.VISIBLE);
            vh4.iv3.setVisibility(View.VISIBLE);
        }

        return view;
    }

    public static class ViewHolder4 {
        private ImageView iv, iv2, iv3, iv4;
        private TextView tv, tv2;

        public ViewHolder4(View view) {
            iv = (ImageView) view.findViewById(R.id.iv_item_moren_vip);
            iv2 = (ImageView) view.findViewById(R.id.iv_item_moren_new);
            iv3 = (ImageView) view.findViewById(R.id.iv_item_moren_vip2);
            iv4 = (ImageView) view.findViewById(R.id.iv_item_moren_new2);
            tv = (TextView) view.findViewById(R.id.tv_item_moren_text);
            tv2 = (TextView) view.findViewById(R.id.tv_item_moren_text2);
        }
    }

}
